package com.ytjj.qmyx.admin.service.impl;

import com.github.pagehelper.PageHelper;
import com.ytjj.qmyx.admin.dao.HotelDao;
import com.ytjj.qmyx.admin.eunm.HotelEnums;
import com.ytjj.qmyx.admin.model.dto.ForumProductDto;
import com.ytjj.qmyx.admin.model.dto.HotelTypeDto;
import com.ytjj.qmyx.admin.model.request.HotelProductRequest;
import com.ytjj.qmyx.admin.model.response.HotelProductResponse;
import com.ytjj.qmyx.admin.service.HotelService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @Description TODO
 * @ClassName HotelServiceImpl
 *
 *
 * @Version 1.0
 **/

@Service
public class HotelServiceImpl implements HotelService {

    @Resource
    private HotelDao hotelDao;

    @Override
    public List<HotelProductResponse> getHotelProductList(HotelProductRequest hotelProductRequest) {
        PageHelper.startPage(hotelProductRequest.getPageNum(), hotelProductRequest.getPageSize());
        return hotelDao.getHotelProductList(hotelProductRequest);
    }

    @Override
    public List<ForumProductDto> searchHotelProduct(Integer productId, String productName) {
        return hotelDao.searchHotelProduct(productId, productName);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void addHotelProduct(Integer productId, String type, Integer sort, Integer status) {
        hotelDao.addHotelProduct(productId, type, sort, status);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void updateHotelProduct(Integer sort, Integer status, Integer id) {
        hotelDao.updateHotelProduct(sort, status, id);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void deleteHotelProduct(Integer id) {
        hotelDao.deleteHotelProduct(id);
    }

    @Override
    public List<HotelTypeDto> getHotelTypeList() {
        List<String> hotelActivityType = HotelEnums.getHotelActivityType();
        return hotelActivityType.stream().map(item -> {
            return new HotelTypeDto()
                    .setHotelType(item)
                    .setHotelTypeName(HotelEnums.getHotelTypeName(item));
        }).collect(Collectors.toList());
    }
}
